<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Run SQL Query</title>
</head>
<body>
    <h1>Run SQL Query</h1>
    <form method="POST">
        <textarea name="sql" rows="5" cols="50">{{ sql }}</textarea><br>
        <input type="submit" value="Run Query">
    </form>
    {% if error %}
    <p style="color: red;">Error: {{ error }}</p>
    {% endif %}
    {% if result is not none %}
    <h2>Result</h2>
    <table border="1">
        <tr>
            {% for col in result.columns %}
            <th>{{ col }}</th>
            {% endfor %}
        </tr>
        {% for row in result.itertuples(index=False) %}
        <tr>
            {% for value in row %}
            <td>{{ value }}</td>
            {% endfor %}
        </tr>
        {% endfor %}
    </table>
    {% endif %}
{#    <a href="{{ url_for('showtables') }}">Back to Tables</a>#}
</body>
</html>
